const express = require("express");
const router = express.Router();
const conf = require("../mod/config");
const request = require("../mod/request");
const map = require("../mod/map");
/* GET users listing. */
router.get('/404', function(req, res) {
  res.render("404", {
    conf:conf
  });
});

router.get('/local', function(req, res,next) {
  request.all(
    [
      { path: "/GetBigBannerList?blockNum=1", clientReq: req },
      { path: "/GetSmallBannerList?blockNum=1", clientReq: req },
      { path: "/GetHotNews?hotType=1&pageIndex=1&pageSize=10", clientReq: req }
    ],
    (data) => {
       res.render("local_index", {
        conf:conf,
        bigBanner:data[0].hasValue == "true" && data[0].data || [],
        smallgBanner:data[1].hasValue  == "true" && data[1].data || [],
        news:data[2].hasValue  == "true" && data[2].data || []
      });
     },
     (error) => {
        res.render("404", {
          conf:conf
        });
     }
  );
});
router.get('/local/p:id', function(req, res,next) {
  var id = req.params.id;
  request.send(
    {
      path:"/GetNewsDetail/"+id,
      callback:(data) => {
        res.render("local_details", {
          conf:conf,
          name:"local",
          detail:data.hasValue  == "true" && data.data || {}
        });
      },error:(err) => {
        res.render("404", {
          conf:conf
        });
      },
      clientReq:req
    });
});

module.exports = router;